package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Medal;
import com.ruoyi.system.service.IMedalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 勋章Controller
 * 
 * @author ruoyi
 * @date 2025-04-25
 */
@RestController
@RequestMapping("/system/medal")
public class MedalController extends BaseController
{
    @Autowired
    private IMedalService medalService;

    /**
     * 查询勋章列表
     */
    @PreAuthorize("@ss.hasPermi('system:medal:list')")
    @GetMapping("/list")
    public TableDataInfo list(Medal medal)
    {
        startPage();
        List<Medal> list = medalService.selectMedalList(medal);
        return getDataTable(list);
    }

    /**
     * 导出勋章列表
     */
    @PreAuthorize("@ss.hasPermi('system:medal:export')")
    @Log(title = "勋章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Medal medal)
    {
        List<Medal> list = medalService.selectMedalList(medal);
        ExcelUtil<Medal> util = new ExcelUtil<Medal>(Medal.class);
        util.exportExcel(response, list, "勋章数据");
    }

    /**
     * 获取勋章详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:medal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(medalService.selectMedalById(id));
    }

    /**
     * 新增勋章
     */
    @PreAuthorize("@ss.hasPermi('system:medal:add')")
    @Log(title = "勋章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Medal medal)
    {
        return toAjax(medalService.insertMedal(medal));
    }

    /**
     * 修改勋章
     */
    @PreAuthorize("@ss.hasPermi('system:medal:edit')")
    @Log(title = "勋章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Medal medal)
    {
        return toAjax(medalService.updateMedal(medal));
    }

    /**
     * 删除勋章
     */
    @PreAuthorize("@ss.hasPermi('system:medal:remove')")
    @Log(title = "勋章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(medalService.deleteMedalByIds(ids));
    }

    // MedalController.java
    @GetMapping("/next")
    public AjaxResult getNextMedal(@RequestParam("currentPoints") Integer currentPoints) {
        Medal nextMedal = medalService.selectNextMedal(currentPoints);
        return AjaxResult.success(nextMedal);
    }



}
